const app = getApp();
Page({
    data: {
        userInfo:app.cache.get('loginUser'),
        professRecordList:[],
        statusList:['未发送通知','发送待响应','已响应未完成流程','已响应','拒绝表白','接受表白']
    },
    goBackToMySelf(){
        swan.navigateTo({
            url:'../mySelf/mySelf'
        })
     },
     goToProfess(){
         swan.navigateTo({
             url:'../../../packageA/pages/request/request'
         })
     },
    getProfessRecordList(){

        swan.request({

            url:app.globalData.URL + `/8100/profess-record/findEntityListByToId/${this.data.userInfo.id}`,
            method: 'get',
            success:res=>{
                if(res.data.code != 200){
                    app.showToastFail(res.data.msg)
                    return;
                }

                this.setData({
                    professRecordList: res.data.data
                })
            }
        })
    },

    toDetial(e){

        console.log('status',e.currentTarget.dataset.status)
        console.log('id',e.currentTarget.dataset.id)
        let status = e.currentTarget.dataset.status;


        if(status == 1){
            swan.navigateTo({
                url: `../../../packageB/pages/response/response?professRecordId=${e.currentTarget.dataset.id}`
            });
        }else {
            swan.navigateTo({
                url: `../../../packageB/pages/chat/chat?toUserId=${e.currentTarget.dataset.from}`
            });
        }
    },

    updateStatus(e){


        let id = e.currentTarget.dataset.id;
        let status = e.currentTarget.dataset.status;
        console.log(id,status)

        swan.request({

            url:app.globalData.URL + `/8100/profess-record/updateStatusById/${id}/${status}`,
            method: 'put',
            success:res=>{
                if(res.data.code != 200){
                    app.showToastFail(res.data.msg)
                    return;
                }

                this.getProfessRecordList()
            }
        })

    },

    onLoad: function () {
        // 监听页面加载的生命周期函数
        this.getProfessRecordList()
    },
    onReady: function() {
        // 监听页面初次渲染完成的生命周期函数
    },
    onShow: function() {
        // 监听页面显示的生命周期函数
    },
    onHide: function() {
        // 监听页面隐藏的生命周期函数
    },
    onUnload: function() {
        // 监听页面卸载的生命周期函数
    },
    onPullDownRefresh: function() {
        // 监听用户下拉动作
    },
    onReachBottom: function() {
        // 页面上拉触底事件的处理函数
    },
    onShareAppMessage: function () {
        // 用户点击右上角转发
    }
});